using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace PureRobot.Digi.ConnectME.JumpStart.SerialFun
{
    internal class DigiHardwareProvider : HardwareProvider
    {
        static DigiHardwareProvider()
        {
            Microsoft.SPOT.Hardware.HardwareProvider.Register(new DigiHardwareProvider());
        }

        override public void GetSerialPins(SerialPort.Serial com, out Microsoft.SPOT.Hardware.Cpu.Pin rxPin, out Microsoft.SPOT.Hardware.Cpu.Pin txPin)
        {
            switch (com)
            {
                case SerialPort.Serial.COM1:
                    rxPin = GpioPins.GPIO_PIN_A3;
                    txPin = GpioPins.GPIO_PIN_A7;
                    break;
                default:
                    throw new NotSupportedException();
            }
        }
    }

    /// <summary>
    /// The actual pins that are used for general purpose input and output (GPIO).
    /// </summary>
    public static class RealGpioPins
    {
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin Gpio1 = (Microsoft.SPOT.Hardware.Cpu.Pin)0;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin Gpio2 = (Microsoft.SPOT.Hardware.Cpu.Pin)1;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin Gpio3 = (Microsoft.SPOT.Hardware.Cpu.Pin)2;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin Gpio4 = (Microsoft.SPOT.Hardware.Cpu.Pin)5;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin Gpio5 = (Microsoft.SPOT.Hardware.Cpu.Pin)6;
    }

    /// <summary>
    /// Digi supplied pin listing.
    /// </summary>
    public static class GpioPins
    {
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A0 = (Microsoft.SPOT.Hardware.Cpu.Pin)0;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A1 = (Microsoft.SPOT.Hardware.Cpu.Pin)1;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A2 = (Microsoft.SPOT.Hardware.Cpu.Pin)2;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A3 = (Microsoft.SPOT.Hardware.Cpu.Pin)3;

        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A5 = (Microsoft.SPOT.Hardware.Cpu.Pin)5;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A6 = (Microsoft.SPOT.Hardware.Cpu.Pin)6;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_A7 = (Microsoft.SPOT.Hardware.Cpu.Pin)7;

        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_C1 = (Microsoft.SPOT.Hardware.Cpu.Pin)9;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_C4 = (Microsoft.SPOT.Hardware.Cpu.Pin)12;
        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_PIN_C5 = (Microsoft.SPOT.Hardware.Cpu.Pin)13;

        /// <summary/>
        public const Microsoft.SPOT.Hardware.Cpu.Pin GPIO_NONE = Microsoft.SPOT.Hardware.Cpu.Pin.GPIO_NONE;
    }

    /// <summary>
    /// Available baud rates for serial communication with the Digi Connect ME's TTL serial port.
    /// </summary>
    public static class BaudRate
    {
        /// <summary/>
        public const SerialPort.BaudRate Baud4800 = (SerialPort.BaudRate)4800;
        /// <summary/>
        public const SerialPort.BaudRate Baud9600 = (SerialPort.BaudRate)9600;
        /// <summary/>
        public const SerialPort.BaudRate Baud19200 = (SerialPort.BaudRate)19200;
        /// <summary/>
        public const SerialPort.BaudRate Baud38400 = (SerialPort.BaudRate)38400;
        /// <summary/>
        public const SerialPort.BaudRate Baud57600 = (SerialPort.BaudRate)57600;
        /// <summary/>
        public const SerialPort.BaudRate Baud115200 = (SerialPort.BaudRate)115200;
        /// <summary/>
        public const SerialPort.BaudRate Baud230400 = (SerialPort.BaudRate)230400;
    }
}

